package com.code.day01.Prepered;

import java.sql.*;
import java.util.Scanner;

public class Demo {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名:");
        String username = sc.nextLine();
        System.out.println("请输入密码:");
        String password = sc.nextLine();

        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://192.168.254.134:3306/msgcenter";
        String user = "root";
        String sqlpassword = "esz8311l";
        Connection connection = DriverManager.getConnection(url, user, sqlpassword);
        Statement statement = connection.createStatement();
        String sql = "select * from user where username=? and userage=?;";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, username);
        preparedStatement.setString(2, password);
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            System.out.println("username = " + resultSet.getString(1) + " userage = " + resultSet.getInt(2));
        }
        statement.close();
        connection.close();
        sc.close();
    }
}
